package com.RedRiver.hospitalsystem.record_service.app.controller;


import cn.hutool.core.bean.BeanUtil;
import com.RedRiver.hospitalsystem.record_service.app.utils.TokenGet;
import com.RedRiver.hospitalsystem.record_service.client.RecordsClient;
import com.RedRiver.hospitalsystem.record_service.client.param.AddResultParam;
import com.RedRiver.hospitalsystem.record_service.client.param.CreateRecordParam;
import com.RedRiver.hospitalsystem.record_service.client.result.SearchRecordByIdResult;
import com.RedRiver.hospitalsystem.record_service.form.AddResultForm;
import com.RedRiver.hospitalsystem.record_service.form.CreateRecordForm;
import com.RedRiver.hospitalsystem.record_service.info.SearchRecordByIdInfo;
import com.RedRiver.hospitalsystem.record_service.service.RecordsService;
import com.RedRiver.hospitalsystem.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.ir.annotations.Ignore;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 龙世超
 * @since 2022-04-26
 */
@RestController
@RequestMapping("/records")
@Api(tags = "病历相关")
public class RecordsController implements RecordsClient {

    @Resource
    private RecordsService recordsService;

    @Resource
    private TokenGet tokenGet;

    @Override
    @ApiOperation("添加病历")
    public Result<?> createRecord(CreateRecordParam recordParam) {
        CreateRecordForm recordForm = BeanUtil.copyProperties(recordParam, CreateRecordForm.class);
        recordForm.setDoctorId(tokenGet.getAccountId());
        return recordsService.addRecord(recordForm);
    }

    @Override
    @ApiModelProperty("根据患者id查询病历")
    public Result<List<SearchRecordByIdResult>> searchRecordByid(Integer id) {
        List<SearchRecordByIdInfo> list=recordsService.findRecord(id);
        List<SearchRecordByIdResult> results = BeanUtil.copyToList(list, SearchRecordByIdResult.class);
        return Result.getInstanceList(SearchRecordByIdResult.class).setData(results);
    }

    @Override
    @ApiOperation("创建医生诊断结果")
    public Result<?> createRecordResult(AddResultParam resultParam) {
        AddResultForm resultForm = BeanUtil.copyProperties(resultParam, AddResultForm.class);
        return recordsService.addRecordResult(resultForm);
    }

}

